package org.hackystat.devcathlon.ui.page.profile.browse;

import static org.junit.Assert.*;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.configuration.ConfigurationException;
import org.hackystat.devcathlon.engine.profile.ProfileManager;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
import org.hackystat.devcathlon.ui.page.profile.ProfilePage;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests Profile Browse.
 * @author Anthony Du
 *
 */
public class TestProfileBrowse extends DevcathlonTestHelper {
  /** Wicket tester. */
  private WicketTester tester;
  
  /**
   * Initialize profile browse test.
   * @throws ConfigurationException when an error occurs
   */
  @Before
  public void setUp() throws ConfigurationException {
    tester = new WicketTester(new DevcathlonApplication());
    tester.startPage(ProfilePage.class);
    
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", "admin@hackystat.org");
    formTester.setValue("password", "admin@hackystat.org");
    formTester.submit();
    tester.assertRenderedPage(ProfilePage.class);
    tester.clickLink("ProfileBrowseLink");
    tester.assertRenderedPage(ProfileBrowsePage.class);
  }
  
  /**
   * Test profiles listing.
   */
  @Test
  public void testProfileBrowseListing() {
    assertNotNull("profile list is not null", 
                     ProfileManager.getInstance().getProfiles());
    assertFalse("profile list is not empty", 
                     ProfileManager.getInstance().getProfiles().isEmpty());
    assertNotNull("should have profile browse panel",
            tester.getTagByWicketId("profileBrowsePanel"));
//    tester.clickLink("profileBrowsePanel:profilesListing:profilesList:0:profileLink");
//    tester.assertRenderedPage(ProfilePage.class);
  }
}
